<template>
  <div >
    <slot></slot>
  </div>
</template>
<script>
    export default {
        name: "ueInbox",
        data() {
            return {
                editor: null,
                defaultConfig: {}
            };
        },
        props: ['catchData', 'config', 'htmlContent', 'ID'], // 接收父组件的方法
        beforeCreate() {
            setTimeout(() => {
                const _this = this;
                let config = Object.assign({}, this.defaultConfig, this.config)
                this.editor = UE.getEditor(this.ID.toString(), config); // 初始化UE
                this.editor.addListener("ready", function () {
                    // _this.editor.setContent(_this.htmlContent); // 确保UE加载完成后，放入内容。
                    _this.$emit('ready');
                });
                this.editor.addListener("contentChange", () => {
                    this.catchData(this.editor.getContent());
                });
            })
        },
        methods: {
            getInit(htmlContent) {
                this.editor.setContent(htmlContent);
            },
            getInsert(htmlContent) {
                this.editor.setContent(_this.htmlContent + htmlContent);
            },
            //重置
            reset() {
                const _this = this;
                setTimeout(() => {
                    _this.editor.setContent('');
                }, 500)
            },
        },
        destroyed() {
            this.editor.destroy();
        }
    };
</script>
